package com.douziit.meilianoa.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.douziit.meilianoa.base.request.PageRequest;
import com.douziit.meilianoa.base.response.ResponseData;
import com.douziit.meilianoa.base.response.ResponseUtil;
import com.douziit.meilianoa.entity.Contact;
import com.douziit.meilianoa.service.ContactService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 联系人管理
 */
@RestController
@RequestMapping("/contact")
public class ContactController {

    @Autowired
    private ContactService contactService;

    /**
     * 添加联系人
     */
    @PostMapping("/addContact")
    public ResponseData addContact(@RequestBody Contact contact){
        contactService.save(contact);
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 联系人列表
     */
    @PostMapping("/listContact")
    public ResponseData listContact(@RequestParam("customerId") Integer customerId){
        List<Contact> list = contactService.list(new QueryWrapper<Contact>().eq("customer_id",customerId));
        return ResponseUtil.jsonSuccess(list);
    }

    /**
     * 删除联系人信息
     */
    @PostMapping("/deleteContact")
    public ResponseData deleteContact(@RequestBody PageRequest req){

        contactService.removeById(req.getContactId());
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 修改联系人信息
     */
    @PostMapping("/changeContact")
    public ResponseData changeContact(@RequestBody Contact contact){
        contactService.updateById(contact);
        return ResponseUtil.jsonSuccess(0);
    }

}
